<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>数组中的哪些方法是响应式的</title>
</head>
<body>

<div id="app">
  <button @click="btnclickpush">btnclickpush</button>
  <button @click="btnclickpop">btnclickpop</button>
  <button @click="btnclicksplice">btnclicksplice</button>
  <button @click="btnclicksort">btnclicksort</button>
  <button @click="btnclickreverse">btnclickreverse</button>
  <button @click="btnclickshift">btnclickshift</button>
  <button @click="btnclickunshift">btnclickunshift</button>
  <h2>注意：通过索引修改数组元素不是响应式的</h2>
  <button @click="btnclickindex">btnclickindex</button>
  <h2>可以使用下面的方法做到响应式</h2>
  <button @click="btnclickVueset">btnclickVueset</button>
  <button @click="btnclicksplice">btnclicksplice</button>

  <ul>
    <li v-for="item in letters">{{item}}</li>
  </ul>
</div>
<script src="../js/vue.js"></script>
<script>
  const app = new Vue({
    el: '#app',
    data: {
      letters: ['a', 'b', 'c', 'd', 'e']
    },
    methods: {
      btnclickpush() {
        this.letters.push('aaaa')
      },
      btnclickpop() {
        this.letters.pop()
      },
      btnclicksplice() {
        this.letters.splice(1,1,'MMM')
      },
      btnclicksort() {
        this.letters.sort()
      },
      btnclickreverse() {
        this.letters.reverse()
      },
      btnclickshift() {
        this.letters.shift()
      },
      btnclickunshift() {
        this.letters.unshift('LLLL')
      },
      btnclickindex() {
        this.letters[0] = 'KKKK'
      },
      btnclickVueset() {
        Vue.set(this.letters, 1, 'UUUUU')
      }


    }

  })
</script>
</body>
</html>
